package plagiarism;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import words.Article;
import words.ArticleResult;
import words.Comparer;
import words.Result;

public class CheckManager {

	private ArrayList<Article> articles;
	private ArrayList<ArticleResult> articleresults;

	public CheckManager() {
		this.articles = new ArrayList<Article>();
		this.articleresults = new ArrayList<ArticleResult>();
	}

	public void operation(ArrayList<String[]> datalists) {
		// to call the seperator to seperate the noun, awl , quotation...
		Seperator seperator = new Seperator();
		for (int i = 0; i < datalists.size(); i++) {
			String[] datalist = datalists.get(i);
			if (!seperator.set_data(datalist)) {
				System.out.println("Error: cannot set the data to the article");
			}
			seperator.seperate();
			this.articles.add(seperator.getArticle());
		}
		// after seperate all the datalists into the article
		// call the checking to do the comparsion
		// checking();
	}

	public void checking() {
		int count = articles.size();
		Comparer comparer = new Comparer();
		for (int i = 0; i < count; i++) {
			Article origin_art = this.articles.get(i);
			comparer.set_origin(origin_art);
			articleresults.add(new ArticleResult(i + 1));
			ArticleResult articleresult = articleresults.get(i);
			for (int j = i + 1; j < count; j++) {
				/*
				 * Step2: to open the Checking to go to check the data
				 * comparsion
				 */
				Article compared_art = this.articles.get(j);
				comparer.set_copy(compared_art);
				comparer.setId(j + 1);
				if (comparer.execute()) {
					Result result = comparer.getResult();
					articleresult.add_result(result);
				}

			}
		}
	}

	public ArticleResult getArtResult(int value) {
		return this.articleresults.get(value);
	}

	public ArrayList<ArticleResult> output_all() {
		return articleresults;

	}
}
